import sys
from PyQt5 import QtCore, QtWidgets, QtCore

# 导入 Qt designer 设计界面
from begin import Ui_MainWindow as begin_Ui
from staff_login import Ui_Staff_login as staff_login_Ui
from register import Ui_Register as register_Ui
from password_management import Ui_PassWord as password_management_Ui
from successfully_loging import Ui_MainWindow as successfully_loging_Ui
# 主窗口
class BeginWindow(QtWidgets.QMainWindow, begin_Ui):
    switch_window1 = QtCore.pyqtSignal() # 跳转信号
    switch_window2 = QtCore.pyqtSignal() # 跳转信号
    switch_window3 = QtCore.pyqtSignal()  # 跳转信号
    def __init__(self):
        super(BeginWindow, self).__init__()
        self.setupUi(self)
        self.staff.clicked.connect(self.goLogin)
        self.newstaff.clicked.connect(self.goRegister)
        self.pushButton_3.clicked.connect(self.goPassword)
    def goLogin(self):
        self.switch_window1.emit()
    def goRegister(self):
        self.switch_window2.emit()
    def goPassword(self):
        self.switch_window3.emit()

# 登录窗口
class LoginWindow(QtWidgets.QMainWindow, staff_login_Ui):
    def __init__(self):
        super(LoginWindow, self).__init__()
        self.setupUi(self)

# 注册窗口
class RegisterWindow(QtWidgets.QMainWindow, register_Ui):
    def __init__(self):
        super(RegisterWindow, self).__init__()
        self.setupUi(self)
#密码管理窗口
class PasswordWindow(QtWidgets.QMainWindow, password_management_Ui):
    def __init__(self):
        super(PasswordWindow, self).__init__()
        self.setupUi(self)

# 利用一个控制器来控制页面的跳转
class Controller:
    def __init__(self):
        pass
    # 跳转到 begin 窗口
    def show_begin(self):
        self.hello = BeginWindow()
        self.hello.switch_window1.connect(self.show_login)
        self.hello.switch_window2.connect(self.show_Register)
        self.hello.switch_window3.connect(self.show_Password)
        self.hello.show()
    # 跳转到 login 窗口, 注意关闭原页面
    def show_login(self):
        self.login = LoginWindow()
        #self.hello.close()
        self.login.show()
    # 跳转到 register 窗口, 注意关闭原页面
    def show_Register(self):
        self.register = RegisterWindow()
        #self.hello.close()
        self.register.show()
    #跳转到 password_management 窗口
    def show_Password(self):
        self.password = PasswordWindow()
        #self.hello.close()
        self.password.show()



def main():
    app = QtWidgets.QApplication(sys.argv)
    controller = Controller() # 控制器实例
    controller.show_begin() # 默认展示的是 hello 页面
    sys.exit(app.exec_())




if __name__ == '__main__':
    main()
